package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import dao.OrderDao;
import model.OrderModel;
import util.C3p0Util;
import util.DBUtil;

public class OrderDaoImpl implements OrderDao {

//	@Override
//	public OrderModel findById(int ordernum) throws Exception {
//		OrderModel order=new OrderModel();
//		Connection connection=DBUtil.getconnection();
//		PreparedStatement ps=connection.prepareStatement("SELECT * FROM orderlist WHERE ordernum=?");
//		ps.setInt(1,ordernum);
//		ResultSet rs = ps.executeQuery();
//		while(rs.next()){
//			order.setOrdernum(rs.getInt(1));
//			order.setRoomtype(rs.getString(4));
//			order.setUsername(rs.getString(5));
//			order.setAllprice(rs.getDouble(6));
//		}
//		return order;
//	}

	@Override
	public List<OrderModel> findByName(String username) throws Exception {
		return C3p0Util.qr.query("select * from orderlist where username='"+username+"'",new BeanListHandler<OrderModel>(OrderModel.class));
	}

@Override
public List<OrderModel> findById(int ordernum) throws Exception {
	return C3p0Util.qr.query("select * from orderlist where ordernum="+ordernum,new BeanListHandler<OrderModel>(OrderModel.class));
}
	
//	@Override
//	public OrderModel findByName(String username) throws Exception {
//		OrderModel order=new OrderModel();
//		Connection connection=DBUtil.getconnection();
//		PreparedStatement ps=connection.prepareStatement("SELECT * FROM orderlist WHERE username=?");
//		ps.setString(1,username);
//		ResultSet rs = ps.executeQuery();
//		
//		while(rs.next()){
//			order.setOrdernum(rs.getInt(1));
//			order.setRoomtype(rs.getString(4));
//			order.setUsername(rs.getString(5));
//			order.setAllprice(rs.getDouble(6));
//		}
//		return order;
//	}

}
